home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / test / thextelt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-30  |  8.2 KB  |  290 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.8 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/test/RCS/thextelt.c,v 1.8 1992/10/30 19:05:24 koziol beta koziol $
  30.  
  31. $Log: thextelt.c,v $
  32.  * Revision 1.8  1992/10/30  19:05:24  koziol
  33.  * Added a "const char *" to strcmp calls to make the SGI ANSI compiler hapy
  34.  *
  35.  * Revision 1.7  1992/07/27  18:40:12  dilg
  36.  * Changed DFACC_ALL to DFACC_RDWR in appropriate places to conform to new
  37.  * handling of access modes by Hopen().
  38.  *
  39.  * Revision 1.6  1992/06/25  18:27:39  chouck
  40.  * Changed output file names
  41.  *
  42.  * Revision 1.5  1992/06/22  23:04:42  chouck
  43.  * Removed calls to fork()
  44.  *
  45.  * Revision 1.4  1992/06/01  18:57:55  chouck
  46.  * Cleaned up output so its clear what is going on
  47.  *
  48.  * Revision 1.3  1992/05/31  15:13:55  mfolk
  49.  * Added several casts (uint8 * and uint16) to keep Convex from complaining.
  50.  *
  51.  * Revision 1.2  1992/05/28  14:24:01  chouck
  52.  * Added casts for calls to Hinquire()
  53.  *
  54.  * Revision 1.1  1992/02/10  20:59:34  chouck
  55.  * Initial revision
  56.  *
  57. */
  58.  
  59. #include "hdf.h"
  60. #define TESTFILE_NAME "t.hdf"
  61. uint8 outbuf[4096], inbuf[4096];
  62.  
  63.  
  64. #define CHECK(ret, val, where) \
  65. {if(ret == val) { fprintf(stderr, "%s failed, line %d, code %d\n", \
  66.                           where, __LINE__, ret); \
  67.                   HEprint(stderr, 0); exit(1);}}
  68.  
  69. int main(argc, argv)
  70.     int argc;
  71.     char *argv[];
  72. {
  73.     int32 fid, fid1;
  74.     int32 aid1, aid2;
  75.     int32 fileid, length, offset, posn;
  76.     uint16 tag, ref;
  77.     int16 access, special;
  78.     int ret, i;
  79.     intn errors = 0;
  80.  
  81.     for (i=0; i<4096; i++) outbuf[i] = (char) (i % 256);
  82.  
  83.     printf("Creating base file %s\n", TESTFILE_NAME);
  84.  
  85.     fid = Hopen(TESTFILE_NAME, DFACC_CREATE, 0);
  86.     CHECK(fid, FAIL, "Hopen");
  87.  
  88.     ret = Hnewref(fid);
  89.     CHECK(ret, FAIL, "Hnewref");
  90.  
  91.     printf("Writing object into base file\n");
  92.     ret = Hputelement(fid, (uint16) 1000, (uint16) 1, 
  93.                       (uint8 *) "element 1000 1 wrong",
  94.                       strlen("element 1000 1 wrong ") + 1);
  95.     CHECK(ret, FAIL, "Hputelement");
  96.  
  97.     printf("Promoting above object to external element in file #1\n\n");
  98.     aid1 = HXcreate(fid, 1000, 1, "t1.hdf");
  99.     CHECK(aid1, FAIL, "HXcreate");
  100.  
  101.     ret = Hseek(aid1, strlen("element 1000 1") + 1, DF_START);
  102.     CHECK(ret, FAIL, "Hseek");
  103.  
  104.     ret = Hwrite(aid1, strlen("correct")+1, (uint8 *) "correct");
  105.     if(ret != strlen("correct") + 1) {
  106.       fprintf(stderr, "Hwrite failed (code %d)\n", ret);
  107.       HEprint(stderr, 0);
  108.       exit(1);
  109.     }
  110.  
  111.     ret = Hendaccess(aid1);
  112.     CHECK(ret, FAIL, "Hendaccess");
  113.  
  114.     printf("Creating an external element in file #2\n");
  115.     aid1 = HXcreate(fid, 1000, 4, "t2.hdf");
  116.     CHECK(aid1, FAIL, "HXcreate");
  117.  
  118.     printf("Writing 2000 bytes to file #2\n\n");
  119.     ret = Hwrite(aid1, 2000, outbuf);
  120.     CHECK(ret, FAIL, "Hwrite");
  121.  
  122.     ret = Hendaccess(aid1);
  123.     CHECK(ret, FAIL, "Hendaccess");
  124.  
  125.     ret = Hnewref(fid);
  126.     CHECK(ret, FAIL, "Hnewref");
  127.  
  128.     printf("Creating an external element in file #3\n");
  129.     aid1 = HXcreate(fid, 1000, 2, "t3.hdf");
  130.     CHECK(aid1, FAIL, "HXcreate");
  131.  
  132.     printf("Writing string 'element 1000 2' to file #3\n\n");
  133.     ret = Hwrite(aid1, strlen("element 1000 2")+1, (uint8 *) "element 1000 2");
  134.     if(ret != strlen("element 1000 2")+1) {
  135.       fprintf(stderr, "Hwrite failed (code %d)\n", ret);
  136.       HEprint(stderr, 0);
  137.       exit(1);
  138.     }
  139.  
  140.     ret = Hendaccess(aid1);
  141.     CHECK(ret, FAIL, "Hendaccess");
  142.  
  143.     printf("Verifying data that was stored to file #2\n");
  144.     ret = Hgetelement(fid, (uint16) 1000, (uint16) 4, inbuf);
  145.     if(ret != 2000) {
  146.       fprintf(stderr, "Incorrect element size returned from Hgetelement: %d\n",
  147.               ret);
  148.       HEprint(stderr, 0);
  149.       exit(1);
  150.     }
  151.  
  152.     for (i=0; i<ret; i++) {
  153.        if (inbuf[i] != outbuf[i]) {
  154.            printf("Wrong data at %d, out %d in %d\n", i, outbuf[i], inbuf[i]);
  155.            errors ++;
  156.          }
  157.        inbuf[i] = '\0';
  158.     }
  159.  
  160.     printf("\nCreating an external element in file #4\n");
  161.     aid1 = HXcreate(fid, 1020, 2, "t4.hdf");
  162.     CHECK(aid1, FAIL, "HXcreate");
  163.  
  164.     printf("Writing 4096 bytes to file #4\n\n");
  165.     ret = Hwrite(aid1, 4096, outbuf);
  166.     if(ret != 4096) {
  167.       fprintf(stderr, "Hwrite failed (code %d)\n", ret);
  168.       HEprint(stderr, 0);
  169.       exit(1);
  170.     }
  171.  
  172.     ret = Hendaccess(aid1);
  173.     CHECK(ret, FAIL, "Hendaccess");
  174.  
  175.     ret = Hclose(fid);
  176.     CHECK(ret, FAIL, "Hclose");
  177.  
  178.     printf("Closing and re-opening base file %s\n", TESTFILE_NAME);
  179.     fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
  180.     CHECK(ret, FAIL, "Hopen");
  181.  
  182.     ret = Hnewref(fid);
  183.     CHECK(ret, FAIL, "Hnewref");
  184.  
  185.     aid1 = Hstartread(fid, 1000, 1);
  186.     CHECK(aid1, FAIL, "Hstartread");
  187.  
  188.     printf("\nInquiring about access element in file #1\n");
  189.     ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
  190.                   &access, &special);
  191.     CHECK(ret, FAIL, "Hinquire");
  192.  
  193.     ret = Hread(aid1, length, inbuf);
  194.     if(ret != length) {
  195.       fprintf(stderr, "Hread failed (code %d)\n", ret);
  196.       HEprint(stderr, 0);
  197.       exit(1);
  198.     }
  199.  
  200.     if(strcmp((const char *)inbuf, "element 1000 1 correct")) {
  201.       fprintf(stderr, "Object stored in file #1 is wrong\n");
  202.       fprintf(stderr, "\t       Is: %s\n", inbuf);
  203.       fprintf(stderr, "\tShould be: element 1000 1 correct\n");
  204.       errors++;
  205.     }
  206.  
  207.     ret = Hnewref(fid);
  208.     CHECK(ret, FAIL, "Hnewref");
  209.  
  210.     ret = Hnextread(aid1, 1000, DFREF_WILDCARD, DF_CURRENT);
  211.     CHECK(ret, FAIL, "Hnextread");
  212.  
  213.     printf("\nInquiring about access element in file #2\n");
  214.     ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
  215.                   &access, &special);
  216.     CHECK(ret, FAIL, "Hinquire");
  217.  
  218.     ret = Hnextread(aid1, DFTAG_WILDCARD, DFREF_WILDCARD, DF_START);
  219.     CHECK(ret, FAIL, "Hnextread");
  220.  
  221.     printf("\nInquiring about access element in file #3\n");
  222.     ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
  223.                   &access, &special);
  224.     CHECK(ret, FAIL, "Hinquire");
  225.  
  226.     ret = Hnextread(aid1, DFTAG_WILDCARD, 3, DF_CURRENT);
  227.     if(ret != FAIL) {
  228.       fprintf(stderr, "Hnextread call should have failed !!!\n");
  229.       errors++;
  230.     }
  231.  
  232.     ret = Hnextread(aid1, DFTAG_WILDCARD, 2, DF_CURRENT);
  233.     CHECK(ret, FAIL, "Hnextread");
  234.  
  235.     printf("\nInquiring about access element in file #4\n");
  236.     ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
  237.                   &access, &special);
  238.     CHECK(ret, FAIL, "Hinquire");
  239.  
  240.     aid2 = Hstartwrite(fid, 1000, 1, 4);
  241.     CHECK(aid2, FAIL, "Hstartwrite");
  242.  
  243.     ret = Hwrite(aid2, 4, (uint8 *) "ABCD");
  244.     if(ret != 4) {
  245.       fprintf(stderr, "Hwrite failed (code %d)\n", ret);
  246.       HEprint(stderr, 0);
  247.       exit(1);
  248.     }
  249.  
  250.     ret = Hendaccess(aid1);
  251.     CHECK(ret, FAIL, "Hendaccess");
  252.  
  253.     ret = Hendaccess(aid2);
  254.     CHECK(ret, FAIL, "Hendaccess");
  255.  
  256.     fid1 = Hopen(TESTFILE_NAME, DFACC_READ, 0);
  257.     CHECK(fid1, FAIL, "Hopen");
  258.  
  259.     ret = Hnewref(fid1);
  260.     CHECK(ret, FAIL, "Hnewref");
  261.  
  262.     ret = Hclose(fid);
  263.     CHECK(ret, FAIL, "Hclose");
  264.  
  265.     ret = Hclose(fid1);
  266.     CHECK(ret, FAIL, "Hclose");
  267.  
  268.     if(errors) 
  269.       fprintf(stderr, "\n\t>>> %d errors were encountered <<<\n\n");
  270.     else
  271.       fprintf(stderr, "\n\t>>> All tests passed <<< \n\n");
  272.  
  273. }
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285. /*
  286.  * Local variables:
  287.  * compile-command: "gcc -g -o thextelt thextelt.c libhdf.a"
  288.  * end:
  289.  */
  290.